package com.ima.web.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Example;
import org.hibernate.sql.JoinType;
import org.springframework.stereotype.Repository;

import com.ima.web.beans.db.Stories;
import com.ima.web.beans.db.SubCategories;
import com.ima.web.dao.StoriesDao;

@Repository
public class StoriesDaoImpl implements StoriesDao{
	
	private SessionFactory sessionFactory;
	
	@Override
	public void save(Stories data) {
		Session s = sessionFactory.getCurrentSession();
		s.save(data);
		
	}

	@Override
	public void delete(Stories data) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<Stories> list(Stories data) {
		Session s = sessionFactory.getCurrentSession();
		Criteria c = s.createCriteria(Stories.class);
		c.add(Example.create(data));
			
		List<Stories> stories = c.list();

		return stories;
	}

	@Override
	public Stories findById(int id) {
		Session s = sessionFactory.getCurrentSession();
		
		Stories story = (Stories)s.load(Stories.class,id);
		s.update(story);
		
		return story;
	}

}
